package pl.grabar.clinic.core.domain.person;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

public class PatientListJsonDeserializer extends StdDeserializer<List<Patient>> {

	private static final long serialVersionUID = -3853291923582263665L;

	public PatientListJsonDeserializer() {
		super(Patient.class);
	}

	@Override
	public List<Patient> deserialize(JsonParser jsonParser, DeserializationContext ctx) throws IOException, JsonProcessingException {
		List<Patient> patients = new ArrayList<Patient>();
		while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
			Patient patient = new Patient();
			patient.setId(jsonParser.getLongValue());
			patients.add(patient);
		}
		return patients;
	}

}